<!--
 * @Author: your name
 * @Date: 2021-02-24 13:53:05
 * @LastEditTime: 2021-05-14 16:14:16
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \systemCenter\src\views\ftpManage\pricingManage\pricingTask\pricingTask_index.vue
-->

<template>
  <div>
    <!-- 日常定价 -->
    <div v-show="currentPage === 'index'">
      <el-row class="pricingTask container">
        <el-col style="margin-right: 10px" class="content-left">
          <!-- 按钮与搜索 -->
          <el-row class="handleBox">
            <!-- 左侧按钮 -->
            <el-col :span="18">
              <el-button @click="addOrEditFunc('1')">新增</el-button>
              <el-button @click="addOrEditFunc('2')">编辑</el-button>
              <el-button @click="deleFunc()">删除</el-button>
              <el-button @click="addOrEditFunc('3')">复制</el-button>
              <el-button @click="toExcute()">执行定价</el-button>
              <el-button @click="toMonitor()">执行监控</el-button>
              <el-button @click="refFunc()">执行记录</el-button>
            </el-col>
            <!-- 右侧查询图标 -->
            <el-col :span="6">
              <div class="handleIconBox">
                <!-- 查询弹框 -->
                <el-popover
                  placement="left-start"
                  trigger="click"
                  popper-class="icon_porper"
                >
                  <div class="search_porper">
                    <el-form
                      :model="searchForm"
                      ref="searchForm"
                      label-width="100px"
                      label-position="right"
                      size="mini"
                    >
                      <el-form-item label="任务编号：" prop="taskCode">
                        <el-input
                          v-model="searchForm.taskCode"
                          style="width: 150px"
                        ></el-input>
                      </el-form-item>
                      <el-form-item label="任务名称：" prop="taskName">
                        <el-input
                          v-model="searchForm.taskName"
                          style="width: 150px"
                        ></el-input>
                      </el-form-item>
                    </el-form>
                    <div style="text-align: center; padding: 10px">
                      <el-button size="mini" @click="searchFunc"
                        >查询</el-button
                      >
                      <el-button
                        size="mini"
                        @click="
                          (searchForm.taskCode = ''), (searchForm.taskName = '')
                        "
                        >重置</el-button
                      >
                    </div>
                  </div>
                  <i
                    class="iconfont icon-sousuo"
                    title="搜索"
                    slot="reference"
                  ></i>
                </el-popover>
                <!-- 字段展示弹框 -->
                <el-popover
                  placement="bottom"
                  width="150"
                  trigger="click"
                  popper-class="icon_porper"
                >
                  <div class="operation_checkbox">
                    <el-checkbox-group v-model="checkList">
                      <el-checkbox
                        v-for="item in textData"
                        :label="item.label"
                        :key="item.prop"
                        >{{ item.label }}</el-checkbox
                      >
                    </el-checkbox-group>
                  </div>
                  <i
                    class="iconfont icon-liebiaoshezhi"
                    title="列表设置"
                    slot="reference"
                  ></i>
                </el-popover>
              </div>
            </el-col>
          </el-row>
          <!-- 列表 -->
          <el-table
            ref="multipleTable"
            :data="tableData"
            style="width: 100%"
            @row-click="rowClick"
          >
            <el-table-column width="55" type="selection"  />

            <el-table-column
              prop="taskCode"
              label="任务编号"
              show-overflow-tooltip
              v-if="columnState[0]"
            />

            <el-table-column
              prop="taskName"
              label="任务名称 "
              show-overflow-tooltip
              v-if="columnState[1]"
            />

            <el-table-column
              prop="positions"
              label="头寸数据 "
              show-overflow-tooltip
              v-if="columnState[2]"
              :formatter="formatterPositions"
            ></el-table-column>

            <el-table-column
              prop="dataDate"
              label="最近定价日期"
              show-overflow-tooltip
              sortable
              v-if="columnState[3]"
              :formatter="
                (row) => (row.dataDate ? timeFormat(row.dataDate) : '-')
              "
            />

            <el-table-column
              prop="nextDataDate"
              label="下一定价日期"
              :formatter="
                (row) => (row.nextDataDate ? timeFormat(row.nextDataDate) : '-')
              "
              show-overflow-tooltip
              sortable
              v-if="columnState[4]"
            >
            </el-table-column>

            <el-table-column
              prop="status"
              label="运行状态"
              show-overflow-tooltip
              sortable
              v-if="columnState[5]"
              :formatter="formatRunStatus"
            ></el-table-column>
          </el-table>
          <!-- 分页插件 -->
          <pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="searchForm.page"
            :page-size="searchForm.size"
            @refresh="searchFunc"
            :total="total"
          ></pagination>
        </el-col>
      </el-row>

      <!-- 新增,编辑 form保单-->
      <el-dialog
        v-dialogDrag
        :title="titleName"
        :visible.sync="addOrEdit"
        width="514px"
      >
        <el-form
          :model="saveForm"
          ref="saveOrEditRef"
          label-width="110px"
          label-position="left"
          :rules="saveFormRules"
        >
          <el-row>
            <el-col :span="24">
              <el-form-item
                label="任务编号："
                prop="taskCode"
                style="width: 85%; height: 32px"
              >
                <el-input
                  v-model="saveForm.taskCode"
                  maxlength="40"
                  placeholder="PRICING_"
                  :disabled="operateType == 2"
                  required
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item
                label="任务名称："
                prop="taskName"
                style="width: 85%; height: 32px"
              >
                <el-input
                  v-model="saveForm.taskName"
                  maxlength="40"
                  required
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="数据日期: " prop="dataDate">
                <el-date-picker
                  v-model="saveForm.dataDate"
                  type="date"
                  style="width: 80%; height: 32px"
                  value-format="yyyy-MM-dd"
                  placeholder=""
                  :disabled="operateType == 2"
                ></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="头寸数据表: " prop="position" required="">
                <div class="treeBoxBig">
                  <div class="treeBox">{{ saveForm.position }}</div>
                  <div class="treeBtnCS" @click="treeBtn"></div>
                </div>
                <!-- </el-form-item>  -->
                <!-- <el-input
                type="textarea"
                :rows="2"
                v-model="saveForm.positions"
                maxlength="40"
                :disabled="operateType == 3"
              ></el-input> -->
                <!-- <el-button @click="excute()">xuanze</el-button> -->
                <!-- <div v-popover:popoverElement class="selectBox"></div> -->
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="saveFormButton(operateType)">确 定</el-button>
          <el-button @click="cancelTne">取 消</el-button>
        </div>
      </el-dialog>

      <!-- 执行定价保单-->
      <el-dialog
        v-dialogDrag
        :title="excuteTitle"
        :visible.sync="excute"
        width="514px"
      >
        <el-form
          :model="excuteForm"
          ref="excuteRef"
          label-width="110px"
          label-position="left"
        >
          <el-row>
            <el-col :span="24">
              <el-form-item label="任务编号：" prop="taskCode">
                <el-input
                  v-model="excuteForm.taskCode"
                  maxlength="40"
                  disabled
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="任务名称：" prop="taskName">
                <el-input
                  v-model="excuteForm.taskName"
                  maxlength="40"
                  disabled
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="数据日期: " prop="dataDate">
                <el-date-picker
                style="width: 100%; height: 32px"
                  v-model="excuteForm.dataDate"
                  type="date"
                  value-format="yyyy-MM-dd"
                ></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="定价情景：" prop="sceneName">
                <el-input
                  v-model="excuteForm.sceneName"
                  maxlength="40"
                  disabled
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="情景版本：" prop="versionNum">
                <el-input
                  v-model="excuteForm.versionNum"
                  maxlength="40"
                  disabled
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="曲线确认状态：" prop="affirm">
                <el-input
                  v-if="excuteForm.affirm == 1 ? true : false"
                  v-model="affirmTrue"
                  maxlength="32"
                  disabled
                ></el-input>
                <el-col
                  v-if="excuteForm.affirm == 0 ? true : false"
                  :span="24"
                  width="40%"
                  >未确认 <el-button @click="affirmPop()">确认曲线</el-button>
                </el-col>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="excutes()">开始定价</el-button>
          <el-button @click="cancelTne">取 消</el-button>
        </div>
      </el-dialog>
      <!-- 头寸取数表 -->
      <el-dialog
        v-dialogDrag
        :title="checktitleName"
        :visible.sync="positionCheckDi"
        width="35%"
        top="2%"
      >
        <positionCheckForm
          ref="positionCheckForm"
          @selectDataFunc="selectDataFunc"
        />
        <div slot="footer">
          <!-- <el-button @click="saveFunc">确 定</el-button> -->
          <el-button @click="positionCheckDi = false">取 消</el-button>
        </div>
      </el-dialog>
      <!-- 定价执行监控页面 --------------------------- -->
      <!-- <el-dialog
      v-dialogDrag
      :title="monitortitleName"
      :visible.sync="monitorDi"
      width="80%"
      top="2%"
    >
      <positionMonitorForm
        ref="positionMonitorForm"
        :monitorForm="monitorForm"
        :taskCode="code"
        :monitorDi="monitorDi"
      /> -->
      <!-- @goBack="goBack" -->
      <!-- <div slot="footer"> -->
      <!-- <el-button @click="saveFunc">确 定</el-button> -->
      <!-- <el-button @click="monitorDi = false">返 回</el-button>
      </div>
    </el-dialog> -->

      <!-- 定价执行记录页面 --------------------------- -->
      <!-- <el-dialog
      v-dialogDrag
      :title="recordtitleName"
      :visible.sync="recordDi"
      width="80%"
      top="2%"
      :append-to-body="true"
    >
      <positionRecordForm ref="recordForm" :code="code" />
      <div slot="footer"> -->
      <!-- <el-button @click="saveFunc">确 定</el-button> -->
      <!-- <el-button @click="recordDi = false">返 回</el-button>
      </div>
    </el-dialog> -->
      <el-dialog
        v-dialogDrag
        :title="affirmtitleName"
        :visible.sync="affirmDi"
        width="80%"
        top="2%"
        :append-to-body="true"
      >
        <positionaffirmForm ref="affirmForm" />
        <div slot="footer">
          <!-- <el-button @click="saveFunc">确 定</el-button> -->
          <el-button @click="affirmDi = false">返 回</el-button>
        </div>
      </el-dialog>
    </div>
    <position-monitor-form
      title="定价执行监控"
      v-if="currentPage === 'monitor'"
      :baseData="toDataRow"
      @backIndex="backIndex"
      @toSubTasks="toSubTasks"
      @toResult = "toResult"
    />
    <!-- @toResult = "toResult" -->
    <!-- 执行记录页面 -->
    <excute-notes
      title="定价执行记录"
      v-if="currentPage === 'excuteNotes'"
      :baseData="toDataRow"
      @backIndex="backIndex"
      @toSubTasks="toSubTasks"
    />
    <!-- 定价子任务页面 --------------------------- -->
    <sub-record-form
      title="定价子任务"
      v-if="currentPage === 'subTasks'"
      :baseData="toDataRow"
      @toExcuteNotes="toExcuteNotes"
      @toEngineTask="toEngineTask"
      @backIndex="backIndex"
    />
    <!-- 定价引擎任务页面 --------------------------- -->
    <engine-task
      title="定价引擎任务"
      v-if="currentPage === 'engineTask'"
      :baseData="toDataRow"
      @toExcuteNotes="toExcuteNotes"
      @toSubTasks="toSubTasks"
      @backLast="backLast"
      @toResult = "toResult"
    />
    <!-- @toResult = "toResult" -->
<!-- 查看结果 -->
    <task-result
     v-if="currentPage === 'taskResult'"
      :baseData="toDataRow"
      :comefrom = "comefrom"
      @toBackLast="backIndex"
    ></task-result>
    <!-- 曲线确认页面 --------------------------- -->
  </div>
</template>
<script>
import { pricingTask } from "@/api/index";
import moment from "moment";
import positionaffirmForm from "./curveDataAffirm_index";
import positionCheckForm from "./position_check";
import positionMonitorForm from "./positionTask_monitor";
import excuteNotes from "./pricingTask_record";
import taskResult from "./pricing_result";
// import sceneMonitorForm from "./sceneTask_monitor";
import subRecordForm from "./pricingTask_subRecord";
import engineTask from "./pricingTask_engineTasks";
export default {
  data() {
    return {
      toDataRow: {},
      // 当前页面显示
      currentPage: "index",
      //确认曲线
      affirmtitleName: "确认曲线",
      affirmDi: false,
      affirmTrue: "已确认",
      //定价执行记录
      recordtitleName: "定价执行记录",
      recordDi: false,
      code: "",
      //定价执行监控
      code: "3",
      name: "",
      monitortitleName: "定价执行监控",
      monitorForm: {},
      monitorDi: false,
      //头寸数据
      position: "",
      //头寸数据表页面
      positionCheckDi: false,
      //头寸表标题
      checktitleName: "头寸数据表",
      excuteTitle: "执行定价",
      //按钮操作标识
      //曲线确认状态
      affirm: "0",
      operateType: 1,
      titleName: "",
      addOrEdit: false,
      //执行定价页面
      excute: false,
      searchForm: {
        page: 1,
        size: 15,
        taskCode: "",
        taskName: "",
      },
      //保存实体
      saveForm: {
        taskCode: "",
        taskName: "",
        dataDate: "",
        positions: [],
        position: "",
      },
      //执行定价
      excuteForm: {
        affirm: 0,
      },
      tableData: [],
      params: [],
      total: 0,
      textData: [
        { prop: "taskCode", label: "任务编号", disabled: true },
        { prop: "taskName", label: "任务名称", disabled: true },
        { prop: "positions[0].pdName", label: "头寸数据", disabled: true },
        { prop: "dataDate", label: "最近定价日期", disabled: true },
        { prop: "nextDataDate", label: "下一定价日期", disabled: true },
        { prop: "status", label: "运行状态", disabled: true },
      ],
      checkList: [],
      //表单字段规则校验
      saveFormRules: {
        taskCode: [
          { required: true, message: "该输入项为必输项", trigger: "blur" },
          {
            pattern: /^(PRICING_[0-9a-zA-Z_]+)$/,
            //     /^(PRICING_[0-9a-zA-Z_]+)$/.test(value.replace(/(^\s*)|(\s*$)/g, "")
            message: "只可输入英文字母、数字和下划线，注：必须以'PRICING_'开头",
            trigger: "blur",
          },
        ],
        taskName: [
          { required: true, message: "该输入项为必输项", trigger: "blur" },
          {
            pattern: /^[\u4E00-\u9FA5A-Za-z0-9（）()\[\]【】{}]{1,40}$/,
            message: "只能输入1-40位的汉字、字母、数字或括号",
            trigger: "blur",
          },
        ],
        position: [
          { required: true, message: "该输入项为必输项", trigger: "blur" },
        ],
        dataDate: [
          { required: true, message: "该输入项为必输项", trigger: "blur" },
        ],
      },
    };
  },
  //引入组件
  components: {
    positionCheckForm,
    positionMonitorForm,
    excuteNotes,
    engineTask,
    subRecordForm,
    positionaffirmForm,
    taskResult,
  },
  created() {
    this.checkListInit();
  },
  computed: {
    columnState() {
      let arr = [],
        arr1 = this.textData,
        arr2 = this.checkList;
      for (let i = 0; i < arr1.length; i++) {
        let flag = false;
        for (let j = 0; j < arr2.length; j++) {
          if (arr1[i].label == arr2[j]) {
            flag = true;
            break;
          }
        }
        arr.push(flag);
      }
      return arr;
    },
  },
  mounted() {
    this.searchFunc();
  },
  watch: {},
  methods: {
    // 返回主页面事件处理
    backIndex(v) {
      this.currentPage = "index";
    },
    // 返回comform
    backLast() {
      this.currentPage = this.comform;
    },
    // 去子任务页面
    toSubTasks(v) {
      if (v) {
        this.toDataRow.pricingCode = v.pricingCode;
      }
      this.currentPage = "subTasks";
    },
    //   // 跳转到查看结果
    toResult(val){
      console.log(val,'val')
      this.toDataRow.pricingCode = val.pricingCode
      this.toDataRow.dataDate = val.dataDate
      this.comefrom = this.currentPage
      this.currentPage = "taskResult"
    },
    // // 数据筛选查看 to 数据筛选
    // viewToFilter() {
    //   this.currentPage = "dataFilter";
    // },
    // 跳去执行记录页面
    toExcuteNotes(val) {
      this.currentPage = "excuteNotes";
    },
    // 跳去引擎任务页面
    toEngineTask(val) {
      if (val) {
        this.toDataRow.pricingCode = val.pricingCode;
        this.toDataRow.dataDate = val.dataDate;
      }
      this.comform = this.currentPage;
      this.currentPage = "engineTask";
    },
    refFunc() {
      let selection = this.$refs.multipleTable.selection;
      if (selection.length != 1) {
        return this.$message.warning("请选择一条数据");
      }
      this.toDataRow = { ...selection[0] };
      this.currentPage = "excuteNotes";
    },
    excutes() {
      let data = {
        taskCode: this.excuteForm.taskCode,
        dataDate: this.excuteForm.dataDate,
      };
    pricingTask.excutes(data).then((res) => {
        if (res.code == 200) {
          return this.$message.success("执行定价成功");
        } else {
          return this.$message.warning("联调执行定价失败");
        }
      });
    },
    affirmPop() {
      this.affirmDi = true;
    },
    goBack(val) {
      this.recordDi = false;
      this.monitorDi = false;
    },
    // refFunc() {
    //   let selection = this.$refs.multipleTable.selection;
    //   if (selection.length != 1) {
    //     return this.$message.warning("请选择一条数据");
    //   }
    //   this.code = selection[0].taskCode;
    //   this.recordDi = true;
    // },
    toMonitor() {
      let selection = this.$refs.multipleTable.selection;
      if (selection.length != 1) {
        return this.$message.warning("请选择一条数据");
      }
      let data = {
        taskCode: selection[0].taskCode,
      };
      pricingTask.toMonitor(data).then((res) => {
        if (res.code == 200) {
          let code = res.data.pricingTask.taskCode;
          let name = res.data.pricingTask.taskName;
          console.log(code, "code");
          this.toDataRow = {
            taskCode: code,
            taskName: name,
            pricingCode: res.data.pricingRecord.pricingCode,
            dataDate: res.data.pricingRecord.dataDate,
            sceneName: res.data.scene.sceneName,
            versionNum: res.data.scene.versionNum,
            affirm: 0,
            refreshRate: "10",
          };
          this.currentPage = "monitor";
        }
      });
    },
    deleFunc() {
      let selection = this.$refs.multipleTable.selection;

      if (selection.length == 0) {
        return this.$message.warning("请选择数据");
      }
      let data = [];

      for (let i = 0; i < selection.length; i++) {
        if(selection[i].status=="RUNNING"){
          this.$message.warning("您选择的定价任务中,定价编号为"+selection[i].taskCode+"的定价任务处于正在执行状态,不可删除！");
          return;
        }
        data[i] = selection[i].taskCode;
      }
      console.log(data, "shanchudeshihouchuandideshujv===");
      this.$confirm("你确定要删除选中的数据吗？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          pricingTask.remove(data).then((res) => {
            if (res.code == 200) {
              this.$message.success("删除成功");
              this.searchFunc();
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    selectDataFunc(val) {
      this.positionCheckDi = false;
      if (val) {
        this.params = val;
        console.log(this.params, "params");
        console.log(this.params.row[0], "params.row[0]");
        this.saveForm.position = "";
        for (let i = 1; i <= this.params.row.length; i++) {
          console.log(this.params.row[i - 1], "forxunhuan");
          console.log(this.saveForm.position, "this.saveForm.positions");

          this.saveForm.position += this.params.row[i - 1].pdName;
        }
        console.log(this.saveForm, "saveform");
        console.log(this.params.row[0].pdName, "params.row.pdName");
      }
    },
    treeBtn() {
      this.positionCheckDi = true;
    },
    //点击执行定价
    toExcute() {
      if (this.$refs.excuteRef) {
        this.$nextTick(() => {
          this.$refs.excuteRef.resetFields();
        });
      }
      let selection = this.$refs.multipleTable.selection;
      if (selection.length != 1) {
        return this.$message.warning("请选择一条数据");
      }
      let data = { taskCode: selection[0].taskCode };
      pricingTask.toExcute(data).then((res) => {
        if (res.code == 200) {
          this.excuteForm = {
            taskCode: res.data.pricingTask.taskCode,
            taskName: res.data.pricingTask.taskName,
            dataDate: res.data.pricingTask.dataDate,
            sceneName: res.data.scene.sceneName,
            versionNum: res.data.scene.versionNum,
            affirm: 0,
          };
          console.log(this.excuteForm, "excuteForm");
        }
      });

      this.excute = true;
    },
    // //判断是否已经确认曲线
    // affirmPop() {},
    //添加
    addOrEditFunc(val) {
      if (this.$refs.saveOrEditRef) {
        this.$refs.saveOrEditRef.resetFields();
      }
      this.titleName = "添加定价任务";
      this.operateType = val;
      //清空数据
      this.saveForm = { taskCode: "PRICING_" };
      if (val == "2" || val == "3") {
        let selection = this.$refs.multipleTable.selection;
        this.titleName = val == "2" ? "修改定价任务" : "复制定价任务";
        if (selection.length != 1) {
          return this.$message.warning("请选择一条数据");
        }
        let taskCode = selection[0].taskCode;
        let params = {
          operateType: val,
          pricingTask: {
            positions: [
              {
                pdName: "",
                pdPostFix: "",
              },
            ],
            taskCode: taskCode,
          },
        };
        pricingTask.toForm(params).then((res) => {
          console.log(res, "编辑页面查询到的数据=============================");
          this.saveForm = res.data.pricingTask;
          // this.saveForm.taskCodePre = "PRICING_" + this.saveForm.taskCode;
          let pdName = "";
          for (let i = 0; i < res.data.pricingTask.positions.length; i++) {
            pdName += res.data.pricingTask.positions[i].pdName;
            if (i < res.data.pricingTask.positions.length - 1) pdName += ", ";
          }
          this.saveForm.position = pdName;
          this.params.row = res.data.pricingTask.positions;
        });
      }
      this.addOrEdit = true;
      //
      //       dataSearch.operateType = val;
      //       caPubDriver.pubDriverToForm(dataSearch).then((res) => {
      //         if (this.operateType == "1") {
      //           this.$set(this.saveForm, "creator", res.data.creator);
      //           this.$set(this.saveForm, "createdTm", res.data.createdTm);
      //         } else {
      //           this.saveForm = res.data;
      //           this.copyForm = res.data;
      //         }
      //       });
    },
    //保存表单
    saveFormButton(operateType) {
      this.$refs.saveOrEditRef.validate((valid) => {
        if (valid) {
          let saveData = {};
          this.$set(saveData, "operateType", this.operateType);
          this.saveForm.positions = this.params.row;
          console.log(this.params, "params");
          this.$set(saveData, "pricingTask", this.saveForm);
          // saveData.pricingTask.taskCode = taskCodePre.slice(8);
          console.log(saveData, "保存实体");
          if (operateType == 1||operateType == 3) {
            pricingTask
              .checkTaskCodeUnique("'" + saveData.pricingTask.taskCode + "'")
              .then((res) => {
                if ("0" == res.data) {
                  let pdfix = this.saveForm.positions[0].pdPostFix;
                  let check = {
                    taskCode: saveData.pricingTask.taskCode,
                    positionsStr: pdfix,
                  };
                  console.log(check, "check==================");
                  pricingTask.checkPositionUnique(check).then((res) => {
                    if ("0" == res.data) {
                      pricingTask.save(saveData).then((res) => {
                        this.$message({
                          message: "保存成功",
                          type: "success",
                        });
                        this.addOrEdit = false;
                        this.searchFunc();
                      });
                    } else {
                      this.$message({
                        message:
                          "选中的头寸表已经被其他定价任务选中，请选择其他头寸表！",
                        type: "warning",
                      });
                    }
                  });
                } else {
                  this.$message({
                    message: "此编码已存在",
                    type: "warning",
                  });
                }
              });
          } else {
            pricingTask.save(saveData).then((res) => {
              this.$message({
                message: "保存成功",
                type: "success",
              });
              this.addOrEdit = false;
              this.saveForm.position = "";
              this.searchFunc();
            });
          }
        }
      });
    },
    cancelTne() {
      this.addOrEdit = false;
      this.excute = false;
    },
    timeFormat(val) {
      if (val) return moment(val).format("YYYY-MM-DD");
      else return "";
    },
    rowClick(row) {
      if (this.$refs.multipleTable) {
        this.$refs.multipleTable.clearSelection();
      }
      this.$refs.multipleTable.toggleRowSelection(row, true);
    },
    checkListInit() {
      this.checkList = this.textData.map((v) => {
        return v.label;
      });
    },
    handleSizeChange(val) {
      this.searchForm.size = val;
      this.searchFunc();
      console.log(val, "每页数");
    },
    handleCurrentChange(val) {
      this.searchForm.page = val;
      this.searchFunc();
      console.log(val, "当前页");
    },
    searchFunc() {
      let dataSearch = this.searchForm;
      console.log(dataSearch, "查询字段");
      console.log(this.searchForm, "参数");
      pricingTask.findAll(dataSearch).then((res) => {
        if (res.code === 200) {
                   this.tableData = res.rows.map(v => {
            let obj = v;
            obj.dataDate = obj.dataDate
              ? moment(obj.dataDate).format("yyyy-MM-DD")
              : "-";
            obj.nextDataDate = obj.nextDataDate
              ? moment(obj.nextDataDate).format("yyyy-MM-DD")
              : "-";
            return obj;
          });
          // this.tableData = res.rows;
          console.log(res.rows, "chasdaoshujv=============");
          this.total = res.total;
        }
      });
    },
    formatRunStatus(row, column) {
      if (row.status == "INIT") {
        return "初始化";
      } else if (row.status == "PREPARING") {
        return "准备中";
      } else if (row.status == "RUNNING") {
        return "运行中";
      } else if (row.status == "FINISH") {
        return "已完成";
      } else if (row.status == "ERROR") {
        return "错误";
      } else if (row.status == "SENDBACK") {
        return "已退回";
      } else if (row.status == "RETRY") {
        return "再次尝试中";
      } else {
        return "";
      }
    },
    formatterPositions(row, column) {
      if (row.positions == "") return "";
      let pdName = "";
      for (let i = 0; i < row.positions.length; i++) {
        pdName += row.positions[i].pdName;
        if (i < row.positions.length - 1) pdName += ", ";
      }
      return pdName;
      console.log(pdName, "pdname=================");
      console.log(row, "row");
    },
  },
};
</script>

<style lang="scss" scoped>
.treeBoxBig {
  // width: 320px;
  width: 80%;
  height: 32px;
  border: 1px solid #ababab;
  border-radius: 4px;
  .treeBox {
    width: 80%;
    height: 32px;
    padding-left: 10px;
    line-height: 32px;
  }
  .treeBtnCS {
    background: url("~@/assets/images/popWindow_arrow.gif");
    background-repeat: no-repeat;
    height: 32px;
    width: 32px;
    position: absolute;
    // left: 296px;
    right: 20%;
    top: 8px;
    cursor: pointer;
  }
}
</style>
<style lang="scss" scoped>
.dialogSearchBox {
  header {
    text-align: center;
    span {
      margin: 0 20px;
    }
  }
}
.selectBox {
  background: url("~@/assets/images/popWindow_arrow.gif");
  background-repeat: no-repeat;
  height: 26px;
  width: 23px;
  position: absolute;
  right: 0;
  top: 5px;
  cursor: pointer;
}
</style>
